package cn.tedu.online.examination.system.service.impl;

import cn.tedu.online.examination.system.entity.User;
import cn.tedu.online.examination.system.exception.IdOrPwdException;
import cn.tedu.online.examination.system.service.ExamService;
import cn.tedu.online.examination.system.ui.EntityContext;

/**
 * @author JokerQ
 * @date 2020/6/12 - 17:55
 */
public class ExamServiceImpl implements ExamService {

    private EntityContext entityContext;

    private User loginUser;

    @Override
    public User login(int id, String pwd) throws IdOrPwdException {
        User user = entityContext.findUserById(id);
        if (user == null){
            throw new IdOrPwdException("没有ID用户");
        }
        if (user.getPasswd().equals(pwd)){
            //记录哪位用户考试
            loginUser = user;
            //登陆成功
            System.out.println("登陆成功");
            return user;
        }
        throw new IdOrPwdException("密码不一致");
    }
}
